package com.yutel.system.repository;

import java.util.HashMap;
import java.util.Map;

/**
 * 业务与数据库的数据类型映射
 *
 */
public class ColumnsBean {

	public final static String TRUE = "是";
	public final static String FALSE = "否";
	public final static ColumnsBean KEY_COLUMN = new ColumnsBean();
	static
	{
		KEY_COLUMN.setFieldName("ID");
		KEY_COLUMN.setBusinName("主键");
		KEY_COLUMN.setFieldType("INT");
		KEY_COLUMN.setNullAble(FALSE);
		KEY_COLUMN.setPrimaryKey(TRUE);
	}

	public final static Map<String, String> BUS_SQLSERVER_TYPE_MAP = new HashMap<String, String>();
	static
	{
		BUS_SQLSERVER_TYPE_MAP.put("INT", "int");
		BUS_SQLSERVER_TYPE_MAP.put("DATETIME", "datetime");
		BUS_SQLSERVER_TYPE_MAP.put("FLOAT", "FLOAT");
		BUS_SQLSERVER_TYPE_MAP.put("SHORT_STRING", "VARCHAR(100)");
		BUS_SQLSERVER_TYPE_MAP.put("LONG_STRING", "VARCHAR(500)");
		BUS_SQLSERVER_TYPE_MAP.put("MAX_STRING", "VARCHAR(MAX)");
		BUS_SQLSERVER_TYPE_MAP.put("IMAGE", "IMAGE");
	}
	private String columnId;
	private String fieldCheck;
	private String fieldType;
	private String fieldCode;
	private String fieldName;
	private String businName;
	/**
	 * TODO 元数据添加 是否可以为空 信息
	 * 是否可以为空
	 */
	private String nullAble = TRUE;
	private String primaryKey = FALSE;

	public String getPrimaryKey() {
		return primaryKey;
	}

	public void setPrimaryKey(String primaryKey) {
		this.primaryKey = primaryKey;
	}

	public String getFieldType() {
		return fieldType;
	}

	public void setFieldType(String fieldType) {
		this.fieldType = fieldType;
	}

	public String getFieldCode() {
		return fieldCode;
	}

	public void setFieldCode(String fieldCode) {
		this.fieldCode = fieldCode;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName.toUpperCase();
	}

	public String getBusinName() {
		return businName;
	}

	public void setBusinName(String businName) {
		this.businName = businName;
	}

	public String getFieldCheck() {
		return fieldCheck;
	}

	public void setFieldCheck(String fieldCheck) {
		this.fieldCheck = fieldCheck;
	}

	public String getNullAble() {
		return nullAble;
	}

	public void setNullAble(String nullAble) {
		this.nullAble = nullAble;
	}

	public String getColumnId() {
		return columnId;
	}

	public void setColumnId(String columnId) {
		if("".equals(columnId))
		{
			columnId = null;
		}
		this.columnId = columnId;
	}

	public String getDbType()
	{
		return BUS_SQLSERVER_TYPE_MAP.get(getFieldType());
	}

	public boolean nullAble()
	{
		return TRUE.equals(getNullAble());
	}

	public boolean primaryKey()
	{
		return TRUE.equals(getPrimaryKey());
	}

}
